package com.cl.crm.pers.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.cl.crm.entity.LossWarning;
import com.cl.crm.myutil.Page;
import com.cl.crm.pers.dao.ILossWarningDao;

public class LossWarningDaoImpl extends BaseDao implements ILossWarningDao {

	public boolean insertLossWarning(LossWarning lw) {
		return this.insert(lw);
	}

	public List<LossWarning> selectLossWarnings(Page page,String customerName,String empName,String state){
		String hql="select lw from LossWarning as lw where lw.lwState like ?";
		List param =new ArrayList();
		param.add(state);
		
		if(customerName !=""){
			hql+=" and lw.customerInfo.ciName like ?";
			param.add(customerName+"%");
		}
		if(empName !=""){
			hql+=" and lw.customerInfo.employeesInfo.empName like ?";
			param.add(empName+"%");
		}
		return this.selectPageHql(hql, param, page);
	}

	public List selectLossWarningNum(String customerName, String empName,String state){
		String hql="select count(lw) from LossWarning as lw where lw.lwState like ?";
		List param =new ArrayList();
		param.add(state);
		if(customerName !=""){
			hql+=" and lw.customerInfo.ciName like ?";
			param.add(customerName+"%");
		}
		if(empName !=""){
			hql+=" and lw.customerInfo.employeesInfo.empName like ?";
			param.add("%"+empName+"%");
		}
		return  this.selectHql(hql, param);
	}

	public boolean updateDeferLoss(int lwId, String deferLoss) {
		String hql="update LossWarning as lw set lw.deferLoss =lw.deferLoss+? where lw.lwId= ?";
		List param = new ArrayList();
		param.add(deferLoss);
		param.add(lwId);
		return this.update(hql, param);
	}

	public boolean updateState(int lwId, String state,String LossOf) {
		String hql="update LossWarning as lw set lw.lwState=?,lw.lwLossof =?,lw.lwTime=? where lw.lwId= ?";
		List param = new ArrayList();
		param.add(state);
		param.add(LossOf);
		param.add(new Date().toLocaleString());
		param.add(lwId);
		return  this.update(hql, param);
	}
	

}
